package com.atguigu.teach.mytask;

import com.sun.org.apache.xpath.internal.functions.FuncTrue;

import java.util.concurrent.*;

class MyThread implements Runnable{

    @Override
    public void run() {

    }

}
class MyThread2 implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"\t"+"---do bin");
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "1024";
    }

}

public class MyCallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask=new FutureTask<>(new MyThread2());
        Thread t1=new Thread(futureTask,"A");
        t1.start();
        Thread t2=new Thread(futureTask,"B");
        t2.start();
        while(!futureTask.isDone()){
            System.out.println("***wait");
        }
        System.out.println(Thread.currentThread().getName()+"\t"+"---do bin");
        System.out.println("futrue = " + futureTask.get());
    }
}
